/**************************************************************************************
*  Component of benchmarking program.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************************/
public class SieveBenchmarkUnit extends BenchmarkUnit {

    public int wPrimes[];
    public int wMaxCandidate;

    public SieveBenchmarkUnit() {
        name = "Sieve";
        wMaxCandidate = 256;
        wPrimes = new int[wMaxCandidate];
    }

    public int execute() {

        int j = 1;
        int k = 0;
        wPrimes[0] = 1;
        wPrimes[1] = 2;
        j = 2;

        for (int i = 3; i < wMaxCandidate; i++) {

            boolean flag;
            k = 1;
            for (flag = true; k < j && flag; k++)
                if (wPrimes[k] > 0 && wPrimes[k] <= i / 2 && i % wPrimes[k] == 0)
                     flag = false;
            if (flag) {
                j++;
                wPrimes[j - 1] = i;
            }
        }

        return j;

    } // end execute()

} // SieveBenchmarkUnit

